//
//  CEDurationPageLog.m
//  CELog_Example
//
//  Created by maoerduo on 2021/2/25.
//  Copyright © 2021 maoerduo. All rights reserved.
//

#import "CEDurationPageLog.h"

@interface CEDurationPageLog()

@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> * log;

@end

@implementation CEDurationPageLog

- (instancetype)initWithPageName:(NSString *)pageName {
    self = [super init];
    if (self) {
        self.pageName = pageName;
        self.log = [@{
            @"event_name":@"pageNameTime",
            @"pageName":pageName
        } mutableCopy];
    }
    return self;
}

- (NSDictionary<NSString *,NSString *> *)content {
    return self.log;
}

- (void)start {
    self.startTime = [NSDate date].timeIntervalSince1970;
}

- (void)stop {
    
    NSDate * now = [NSDate date];
    
    self.duration += now.timeIntervalSince1970 - self.startTime;
    
    self.log[@"session_time"] = [NSString stringWithFormat:@"%@", @(self.duration)];
    
}

- (void)pause {
    
    NSDate * now = [NSDate date];
    
    self.duration += now.timeIntervalSince1970 - self.startTime;
    
}

@end
